<!--
 * Description: PMB 指派组件
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Qiuxue.Wu
 * Date: 2020/06/1 18:12
-->

<template>
  <div>
    <!--数据表单-->
    <el-form label-width="90px" :model="formData" size="mini">
      <el-row>
        <!--FD编号-->
        <el-col :span="12">
          <el-form-item :label="$t('FdData.fdId')">
            <span>{{ formData.fdId }}</span>
          </el-form-item>
        </el-col>

        <!--FD版本-->
        <el-col :span="12">
          <el-form-item :label="$t('FdData.version')">
            <span>{{ formData.version }}</span>
          </el-form-item>
        </el-col>

        <!--FD名称-->
        <el-col :span="12">
          <el-form-item :label="$t('FdData.fdName')">
            <span>{{ formData.fdName }}</span>
          </el-form-item>
        </el-col>

        <!--tempModel-->
        <el-col :span="12">
          <el-form-item label="temp Model">
            <span>{{ formData.tempModel }}</span>
          </el-form-item>
        </el-col>

        <!--PBM负责人-->
        <el-col :span="24">
          <el-form-item :label="$t('FdData.pbmOwner')">
            <el-select
              v-model="formData.pbmOwner"
              clearable
              filterable
              :placeholder="$t('select.placeholder')"
            >
              <el-option
                v-for="item in pmbList"
                :key="item.userId"
                :label="item.userName"
                :value="item.userId"
              >
                <span style="float: left;">{{ item.userName }}</span>
                <span style="float: right; color: #b4b4b4; font-size: 12px">
                  {{ item.bu + ' ' + item.team }}
                </span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <!--备注-->
        <el-col :span="24">
          <el-form-item :label="$t('FdData.remark')">
            <el-input
              v-model="formData.remark"
              v-blur:remark="formData"
              clearable
              :placeholder="$t('input.placeholder')"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <span style="display: block;text-align: center;margin-top: 5px">
      <!--取消按钮-->
      <el-button size="medium" @click="cancel">{{ $t('button.cancel') }}</el-button>
      <!--保存按钮-->
      <el-button :loading="isRequesting" size="medium" type="primary" @click="save">
        {{ $t('button.save') }}
      </el-button>
    </span>
  </div>
</template>

<script>
import { fdAppoint } from '@/api/quote/fd'

export default {
  name: 'FdAppointEdit',
  props: {
    inputData: {
      default: () => null,
      type: Object
    }
  },
  data() {
    return {
      // 正在查询
      isRequesting: false,
      formData: {}
    }
  },
  computed: {
    pmbList() {
      const sessionPost = this.$store.getters['post/getSessionPost']
      if (sessionPost.postId === 'P0') {
        return this.$store.getters['user/getSubPbmUserSimpleCollectsByBu'](this.inputData.bu)
      } else {
        return this.$store.getters['user/getSubPbmUserSimpleCollects']
      }
    }
  },
  mounted() {
    this.pageDataInit()
  },
  methods: {
    async pageDataInit() {
      this.formData = this.$deepCopy(this.inputData)
    },
    async save() {
      try {
        this.isRequesting = true
        await fdAppoint(
          {
            fdId: this.formData.fdId,
            pbmOwner: this.formData.pbmOwner,
            version: this.formData.version
          },
          { msgSuccess: true, msgError: true }
        )
        this.$emit('save')
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    cancel() {
      this.$emit('cancel')
    }
  }
}
</script>

<style scoped></style>
